package com.itheima.article.controller;

import com.itheima.article.pojo.ApAuthor;
import com.itheima.article.service.ApAuthorService;
import com.itheima.common.vo.ResultVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author danzhiheng
 * @version 1.1
 * @date 2023/2/4 19:35
 */
@RestController
public class ApiController {

    @Resource
    private ApAuthorService apAuthorService;

    /**
     * 通过apUserId与wmUserId查询作者信息
     * @param apUserId app用户id
     * @param wmUserId 自媒体用户id
     * @return
     */
    @GetMapping("/api/apAuthor/{apUserId}/{wmUserId}")
    public ResultVo<ApAuthor> getByApUserIdWmUserId(
            @PathVariable(value = "apUserId") Long apUserId,
            @PathVariable(value = "wmUserId") Long wmUserId){
        ApAuthor author = apAuthorService.getByApUserIdWmUserId(apUserId, wmUserId);
        return ResultVo.ok(author);
    }

    /**
     * 添加自媒体人
     * @param apAuthor
     * @return
     */
    @PostMapping("api/apAuthor/add")
    public ResultVo<ApAuthor> add(@RequestBody ApAuthor apAuthor){
        apAuthorService.save(apAuthor);
        return ResultVo.ok("操作成功！");
    }
}
